package com.zr.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.zr.common.utils.urora.JpushClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zr.system.domain.SysNotice;
import com.zr.system.mapper.SysNoticeMapper;
import com.zr.system.service.ISysNoticeService;

/**
 * 公告 服务层实现
 * 
 *
 */
@Service
public class SysNoticeServiceImpl implements ISysNoticeService
{
    @Autowired
    private SysNoticeMapper noticeMapper;

    /**
     * 查询公告信息
     * 
     * @param noticeId 公告ID
     * @return 公告信息
     */
    @Override
    public SysNotice selectNoticeById(Long noticeId)
    {
        return noticeMapper.selectNoticeById(noticeId);
    }

    /**
     * 查询公告列表
     * 
     * @param notice 公告信息
     * @return 公告集合
     */
    @Override
    public List<SysNotice> selectNoticeList(SysNotice notice)
    {
        return noticeMapper.selectNoticeList(notice);
    }

    /**
     * 新增公告
     * 
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int insertNotice(SysNotice notice)
    {
        int result = noticeMapper.insertNotice(notice);
        List<String> registrationIds = new ArrayList<String>();
        registrationIds.add("1507bfd3f72d4596394");
        List<String> registrationAlias = new ArrayList<String>();
        registrationAlias.add("Ceshi");
        JpushClientUtil.sendToRegistrationIds(registrationIds,"来自疫情流调平台的最新通告:"+notice.getNoticeTitle(), notice.getNoticeTitle(), notice.getNoticeContent(), "扩展字段");
        JpushClientUtil.sendToAlias(registrationAlias,"来自疫情流调平台的最新通告:"+notice.getNoticeTitle(), notice.getNoticeTitle(), notice.getNoticeContent(), "扩展字段");
        return result;
    }

    /**
     * 修改公告
     * 
     * @param notice 公告信息
     * @return 结果
     */
    @Override
    public int updateNotice(SysNotice notice)
    {
        return noticeMapper.updateNotice(notice);
    }

    /**
     * 删除公告对象
     * 
     * @param noticeId 公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeById(Long noticeId)
    {
        return noticeMapper.deleteNoticeById(noticeId);
    }

    /**
     * 批量删除公告信息
     * 
     * @param noticeIds 需要删除的公告ID
     * @return 结果
     */
    @Override
    public int deleteNoticeByIds(Long[] noticeIds)
    {
        return noticeMapper.deleteNoticeByIds(noticeIds);
    }

    /**
     * 获取最新公告信息
     * @return  结果
     */
    @Override
    public SysNotice selectLatestNotice() {
        return noticeMapper.selectLatestNotice();
    }

    /**
     * 获取最新五条详细公告
     * @return
     */
    @Override
    public List<SysNotice> selectLatestNoticeFive() {
        return noticeMapper.selectLatestNoticeFive();
    }
}
